#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll N=1e4;
ll ans=0,cur=0;
struct fac
{
  ll s;
  ll a;
  ll e;
  ll total;
};
int main()
{
  ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
  fac f[N];
  int n=0;cin>>n;
  for(int i=0;i<n;++i)
  {
    cin>>f[i].s>>f[i].a>>f[i].e;
    f[i].total=f[i].s+f[i].a+f[i].e;
  }
  sort(f, f + n, [](const fac &x, const fac &y) {
        return x.total < y.total;
    });
  for(int i=0;i<n;++i)
  {
    ans+=f[i].s+f[i].a+cur;
    cur+=f[i].total;
  }
  cout<<ans<<endl;
  return 0;
}
